#include <iostream>
using namespace std;

struct Node
{
    int data;
    Node *next;
    Node(int d)
    {
        data = d;
        next = nullptr;
    }
};

class List
{
private:
    /* data */

    Node *head;

    void create_list()
    {
        this->head = nullptr;
    }

    void clear()
    {
        Node *p = this->head;
        while (p)
        {
            Node *next = p->next;
            delete p;
            p = next;
        }
    }

public:
    List()
    {
        create_list();
    }
    ~List() { clear(); }

    void erase(const int &d)
    {
        Node *p = this->head;
        Node *last = this->head;
        for (; p->data != d; p = p->next)
        {
            last = p;
        }
        Node *next = p->next;
        delete p;
        last->next = next;
    }

    void insert(const int &d)
    {
        Node *new_data = new Node(d);
        Node *next = this->head;
        new_data->next = next;
        this->head = new_data;
    }

    void walk_through()
    {
        for (Node *p = this->head; p != nullptr; p = p->next)
        {
            cout << p->data;
            cout << "\n";
        }
    }
};
